<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box {
        background-color: green;
        /* padding:25% 0 */
        /* 前提 宽度是viewport */
        height: 50vw;
    }
</style>
<body>
    <div class="box"></div>
    <script>
        const oBox = document.querySelector('.box');
        window.onload = function () {
            oBox.style.height = (oBox.offsetWidth/2) + 'px'
            // 发散思维
        }
        window.onresize =  function () {
            oBox.style.height = (oBox.offsetWidth/2) + 'px'
            // 发散思维
        }
    </script>
</body>
</html>